package com.atguigu.gmall.common.config;

import com.atguigu.gmall.common.util.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice //  @ControllerAdvice+@ResponseBody
public class GlobalExceptionHandler {

    //处理运行时异常
    @ExceptionHandler(RuntimeException.class)
    public Result error(RuntimeException e){
        log.error("全局运行时异常，{}", e);
        return Result.fail();
    }

    //处理异常
    @ExceptionHandler(Exception.class)
    public Result error(Exception e){
        log.error("全局异常，{}", e);
        return Result.fail();
    }
}
